package com.nacos.config.listenerService;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.listener.NamingEvent;

import java.io.IOException;
import java.util.Properties;

/**
 * @author chn
 * @version 1.0
 * @Feature: 取消监听服务
 * @data 2024/9/12 17:12
 */
public class unListenerService {
    public static void main(String[] args) throws NacosException, IOException {
        Properties properties = new Properties();
        properties.put("serverAddr", "localhost:8848");
        properties.put("username", "nacos");
        properties.put("password", "nacos");

        NamingService namingService = NacosFactory.createNamingService(properties);
        namingService.unsubscribe("test1", event -> {
            if (event instanceof NamingEvent){
                System.out.println(((NamingEvent) event).getServiceName());
                System.out.println(((NamingEvent) event).getInstances());
            }
        });
    }
}
